package com.taojie.graduation.controller;

import com.taojie.graduation.domain.Ordert;
import com.taojie.graduation.service.api.OrdertService;
import com.taojie.graduation.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@Api(tags = {"订单接口"})
@RequestMapping("ordert")
public class OrdertController {
    @Resource
    private OrdertService ordertService;

    @ApiOperation("分页查询")
    @GetMapping("{page}/{size}")
    public Result page(@PathVariable("page") int page, @PathVariable("size") int size){
        return ordertService.findOrdertPage(page, size);
    }

    @ApiOperation("根据id查询订单")
    @GetMapping("{id}")
    public Result findById(@PathVariable("id") Integer id){
        return ordertService.findOrdertById(id);
    }

    /*@ApiOperation("根据id更新订单")
    @PutMapping("{id}")
    public Result updateById(@PathVariable("id") Integer id,@RequestBody Ordert ordert){
        ordert.setId(id);
        return ordertService.updateById(ordert);
    }*/

/*
    @ApiOperation("根据id删除订单")
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id")Integer id){
        return ordertService.deleteById(id);
    }
*/

    @ApiOperation("添加订单")
    @PostMapping("{userid}/{productid}/{storeid}")
    public Result addr(
            @PathVariable("userid")Integer userid,
            @PathVariable("productid") Integer productid,
            @PathVariable("storeid") Integer storeid,
            @RequestBody Ordert ordert
    ) {
        return ordertService.add(ordert, userid, productid, storeid);
    }
    
}
